import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type UserProfileType } from "./profile";
import { type CityType } from "../system/city";

const REGIONAL_AGENT_BASE_URL = "/api";

export const RegionalAgentAPI = {
  getRegionalAgentList: (params: RegionalAgentListQuery) => {
    return request.get<any, ListResponse<RegionalAgentItemType>>(
      `${REGIONAL_AGENT_BASE_URL}/internal/RegionalAgent/`,
      { params }
    );
  },
  getRegionalAgentDetail: (id: number) => {
    return request.get(`${REGIONAL_AGENT_BASE_URL}/internal/RegionalAgent/${id}/`);
  },
  createRegionalAgent: (data: Partial<RegionalAgentForm>) => {
    return request.post(`${REGIONAL_AGENT_BASE_URL}/internal/RegionalAgent/`, data);
  },
  updateRegionalAgent: (data: Partial<RegionalAgentForm>) => {
    return request.put(`${REGIONAL_AGENT_BASE_URL}/internal/RegionalAgent/${data.id}/`, data);
  },
  deleteRegionalAgent: (id: number) => {
    return request.delete(`${REGIONAL_AGENT_BASE_URL}/internal/RegionalAgent/${id}/`);
  },
};

export type RegionalAgentListQuery = {} & ListQuery;

export type RegionalAgentItemType = {
  id: number;
  province: CityType;
  city: CityType;
  district: CityType;
  user: UserProfileType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  name: string;
};

export type RegionalAgentForm = {
  id?: number;
  name: string;
  user: string;
  province?: number;
  city?: number;
  district?: number;
};

export default RegionalAgentAPI;
